package com.example.translateappjava.Service.FoodCalories;

import android.app.Activity;

public class FoodCaloriesHelper {
    private Activity activity;
    private FoodCaloriesListener foodCaloriesListener;

    public interface FoodCaloriesListener{
        void getFoodCaloriesResponse(String response);
    }

    public FoodCaloriesHelper(Activity activity){
        this.activity = activity;
    }

    public void setFoodCaloriesListener(FoodCaloriesListener foodCaloriesListener) {
        this.foodCaloriesListener = foodCaloriesListener;
    }

    public void FoodCaloriesRequest(String message){
        new Thread(new Runnable() {
            @Override
            public void run() {
                String response = getFoodCaloriesResponse(message);
                if(response!=null)
                {
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            foodCaloriesListener.getFoodCaloriesResponse(response);
                        }
                    });
                }
            }
        }).start();
    }

    public String getFoodCaloriesResponse(String message){
        FoodCaloriesImplication foodCaloriesImplication = new FoodCaloriesImplication();
        return foodCaloriesImplication.getFoodCaloriesResponse(message);
    }
}
